package com.weipai.springboot.module.controller;

import com.weipai.springboot.model.Test;
import com.weipai.springboot.module.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/07/26 14:25
 */
@RestController//表明这是一个rest风格的接口
@RequestMapping("/test/")
public class TestController {
    
    @Autowired
    private TestService testService;

    /**
     * @Responsebody注解作用就是将对象转换成json字符串，无需jsonobject.tostring方法使用
     * @param id
     * @return
     */
    @GetMapping("/index")
    public Map<String,Object> getNameById(Integer id)
    {
        return testService.getNameById(id); 
    }

    /**
     * 保存接口
     * @param id
     * @param name
     */
    @PostMapping("/save")
    public void save(Integer id,String name)
    {
        Test test = new Test();
        test.setId(id);
        test.setName(name);
        testService.saveTest(test);
    }
    
}
